package com.fulin.netty;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

/**
 * handlers a serve-side channel.
 * @author fulin16
 *
 */
public class DiscardServerHandler extends ChannelInboundHandlerAdapter{
	
	/**
	 * 将结束
	 */
//	@Override
//	public void channelRead(ChannelHandlerContext ctx,Object msg){
//		ByteBuf in = (ByteBuf)msg;
//		try{
//			while( in.isReadable()){
//				System.out.print((char)in.readByte());
//				System.out.flush();
//			}
//		}finally{
//			ReferenceCountUtil.release(msg);
//		}
//	}
	
	@Override
	public void channelRead(ChannelHandlerContext ctx,Object msg){
		ctx.write(msg);
		ctx.flush();
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause){
		//Close the connection when an excepion is raised.
		cause.printStackTrace();
		ctx.close();
	}
	
}
